package org.ktjy.springbootsecurity.handle;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import java.io.IOException;

public class MyAuthenticationSuccessHandler implements AuthenticationFailureHandler {
    private final String url;
    public  MyAuthenticationSuccessHandler(String url) {
        this.url = url;
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request,
    HttpServletResponse response, AuthenticationException  exception)
        throws IOException, ServletException {
        // 重定向跳转到登录页面
        response.sendRedirect(url);
    }
}
